﻿using System;
#if (WINRT)
using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Interactivity;
using Windows.UI.Xaml.Data;
#else
using System.Windows.Markup;
using System.Windows.Input;
using System.Windows;
#endif

namespace nRoute.Components
{
    public class PageCommand
        : VisualCommandBase
    {
        public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand),
            typeof(PageCommand), new PropertyMetadata(Utilities.Compatability.DP_UNSET_VALUE));

        public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(Object),
            typeof(PageCommand), new PropertyMetadata(Utilities.Compatability.DP_UNSET_VALUE));

#region Properties

        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        public Object CommandParameter
        {
            get { return GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

#if (WINRT)

        [Category("Common Properties")]
        [CustomPropertyValueEditor(CustomPropertyValueEditor.PropertyBinding)]
        public Binding CommandBinding
        {
            get { return GetBinding(CommandProperty); }
            set { SetBinding<ICommand>(CommandProperty, value); }
        }

        [Category("Common Properties")]
        [CustomPropertyValueEditor(CustomPropertyValueEditor.PropertyBinding)]
        public Binding CommandParameterBinding
        {
            get { return GetBinding(CommandParameterProperty); }
            set { SetBinding<Object>(CommandParameterProperty, value); }
        }

#endif

#endregion

#region Overrides

        public override void Execute()
        {
            if (this.Command != null) this.Command.Execute(this.CommandParameter);
        }

#endregion

    }
}
